package com.maben.redis.task;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务：定时发订阅消息
 */
@Component
public class SendTimer {
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Scheduled(fixedDelay = 1000)
    public void sendTimer(){
        redisTemplate.convertAndSend("chat", String.valueOf(Math.random()));
    }

    @Scheduled(fixedDelay = 1000)
    public void sendTimer2(){
        redisTemplate.convertAndSend("chat2", String.valueOf(Math.random()));
    }
}
